/**
 * (C) Copyright 2012 ZWW
 */
package main;

import java.lang.reflect.InvocationTargetException;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

import com.ibm.icu.text.SimpleDateFormat;

import cputils.CPHMTBService;
import cputils.XmlUtils;

/**
 * @author ZWW
 * @date 2014-3-15 下午8:52:38
 * @version V1.0
 */
public class MainConsole {
									   //1      2      3
	public static String[] weekDay = {"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
	public static String[] game = {"SSQ","DLT"};
	public static String[] gameNo = {"101","201"};
	public static List<String> issueList = null;
	
	public static void main(String[] args) {
		XmlUtils utils = new XmlUtils();
		CPHMTBService service = new CPHMTBService();
		Calendar c = Calendar.getInstance();
		//c.setTime(new SimpleDateFormat("yyyy-MM-dd").parse("2014-03-16"));
		int week = c.get(Calendar.DAY_OF_WEEK);
		String game = "DLT";
		String gameNo = "201";
		if (week == 1 || week == 3 || week == 5) {
			game = "SSQ";
			gameNo = "101";
		}
		Map<String, Object> infomMap = service.lastIssuoInfo(game);
		issueList = (List<String>) infomMap.get("issueList");
		help();
		String onsaleIssueNo = (String) infomMap.get("onsaleIssueNo");
		System.out.println(new SimpleDateFormat("yyyy-MM-dd E").format(c.getTime())
				+" "+game+" onsaleIssueNo:"+onsaleIssueNo);
		while(true){
			System.out.print("Input keyword:");
			Scanner sca = new Scanner(System.in);  
			String queryStr = sca.next();
			if ("0".equals(queryStr)) {
				System.exit(0);
			}else if("1".equals(queryStr)) {
				
			}else {
				System.out.println(queryStr);
				String[] con = queryStr.split("-");
				if (con.length != 2) {
					continue;
				}
				game = con[0];
				onsaleIssueNo = con[1];
				Class<?> class1 = utils.getClass();
				try {
					class1.getMethod("import"+game+"Data", Integer.class,Integer.class).invoke(utils, 0,Integer.parseInt(onsaleIssueNo));
				} catch (IllegalAccessException e) {
					e.printStackTrace();
				} catch (IllegalArgumentException e) {
					e.printStackTrace();
				} catch (InvocationTargetException e) {
					e.printStackTrace();
				} catch (NoSuchMethodException e) {
					e.printStackTrace();
				} catch (SecurityException e) {
					e.printStackTrace();
				}
				
			}
		}

	}
	
	private static void help(){
		for (int i=0,size=issueList.size();i<size;i++) {
			System.out.println((i+1)+":"+issueList.get(i));
		}
		System.out.println("101:SSQ\n201:DLT");
	}

}
